<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-yellow sidebar-mini">
<section class="content-header">
    <h1>排产任务池</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" class="form-horizontal">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        项目编号
                                    </label>
                                    <label class="control-label">
                                        <input name="propProdNo" class="form-control" type="text" maxlength="255"
                                               value=""
                                               placeholder="请输入项目编号"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        项目名称
                                    </label>
                                    <label class="control-label">
                                        <input name="prodName" class="form-control" type="text" maxlength="255"
                                               placeholder="请输入项目名称"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        安装地点
                                    </label>
                                    <label class="control-label">
                                        <input name="insSite" class="form-control" type="text" maxlength="255"
                                               placeholder="请输入安装地点"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        需方
                                    </label>
                                    <label class="control-label">
                                        <input name="customer" class="form-control" type="text" maxlength="255"
                                               placeholder="请输入需方"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        提交状态
                                    </label>
                                    <label class="control-label">
                                        <select name="status" class="form-control">
                                            <option value="">全部</option>
                                            <option value="2">已提交</option>
                                            <option value="1" selected="selected">未提交</option>
                                        </select>
                                    </label>
                                </div>
<!--                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">-->
<!--                                    <label class="control-label">-->
<!--                                        是否变更-->
<!--                                    </label>-->
<!--                                    <label class="control-label">-->
<!--                                        <select name="propIsCha" class="form-control">-->
<!--                                            <option value="" selected="selected">全部</option>-->
<!--                                            <option value="2">否</option>-->
<!--                                            <option value="1">是</option>-->
<!--                                        </select>-->
<!--                                    </label>-->
<!--                                </div>-->
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        生产完成状态
                                    </label>
                                    <label class="control-label">
                                        <select name="productionCompletionStatus" class="form-control">
                                            <option value="">全部</option>
                                            <option value="1" selected="selected">未完成</option>
                                            <option value="2">已完成</option>
                                        </select>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">交货时间</label>
                                    <label class="control-label">
                                        <input type="text" class="form-control datepicker" name="startTime"
                                               readonly="readonly"/>
                                        <span> 至 </span>
                                        <input type="text" class="form-control datepicker" name="endTime"
                                               readonly="readonly"/></label>
                                </div>
<!--                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">-->
<!--                                    <label class="control-label">机加完成时间</label>-->
<!--                                    <label class="control-label">-->
<!--                                        <input type="text" class="form-control datepicker" name="macStartTime"-->
<!--                                               readonly="readonly"/>-->
<!--                                        <span> 至 </span>-->
<!--                                        <input type="text" class="form-control datepicker" name="macEndTime"-->
<!--                                               readonly="readonly"/></label>-->
<!--                                </div>-->
                                <button id="btn-search" type="button" class="btn btn-success">
                                    搜索
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div id="toolbar" class="row">
                    <button shiro:hasPermission="pro:equipment:commit" onclick="submitProdOrd('')"
                            class="btn btn-success">批量提交
                    </button>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    let table, tempTable, tempData = new Array(), currentProject;
    $(function () {
        /**
         * 加载列表
         */
        loadTable();
        /**
         * 表格搜索
         */
        $("#btn-search").click(function () {
            js.table.search(table);
        });
    });

    /**
     * 重新加载
     */
    function reloadTable() {
        js.table.refresh(table);
    }

    /**
     * 加载列表
     */
    function loadTable() {
        table = js.table.init({
            url: ctx + "task/scheduling/list",
            showColumns: true,
            showExport: true,
            columns: [
                {
                    checkbox: true,
                    width: '30px',
                    formatter: function (value, row, index) {
                        // 正常提报并且数据正常状态可以提交选择
                        if ((row.proStatus === 1 || row.proStatus === 4) && row.schedulingStatus === 3) {
                            return {disabled: false}
                        } else {
                            return {disabled: true}
                        }
                    }
                },
                {
                    title: '序号', width: '60',
                    formatter: function (value, row, index, field) {
                        var pageSize = table.bootstrapTable('getOptions').pageSize;
                        var pageNumber = table.bootstrapTable('getOptions').pageNumber;
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                }
                ,


                {
                    title: '项目编号', field: 'propProdNo', width: '120',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '项目名称', field: 'prodName', width: '160',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '数量', field: 'propProdNum',width: '60',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '需方', field: 'customer',width: '160',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '安装地点', field: 'insSite',width: '160',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '交货时间', field: 'prodDelDat', width: '90'
                },
                {
                    title: '是否<br>重点', field: "prodIsKey",width: '60',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            if (parseInt(value) === 1) {
                                return '是';
                            } else {
                                return '否';
                            }
                        } else {
                            return '--';
                        }
                    }
                }
                // ,
                // {
                //     title: '是否变更', field: "propIsCha",
                //     formatter: function (value, row, index) {
                //         if (value != null) {
                //             if (parseInt(value) === 1) {
                //                 return '是';
                //             } else {
                //                 return '否';
                //             }
                //         } else {
                //             return '否';
                //         }
                //     }
                // }
                ,
                // {
                //     title: '排产状态', field: "schedulingStatus",width: '90',
                //     formatter: function (value, row, index) {
                //         if (value != null) {
                //             if (value === 1) {
                //                 return '<label class="badge label-default">未排产</label>';
                //             } else if (value === 2) {
                //                 return '<label class="badge label-warning">排产中</label>';
                //             } else if (value === 3) {
                //                 return '<label class="badge label-success">已排产</label>';
                //             }
                //         } else {
                //             return '--';
                //         }
                //     }
                // },

                // {
                //     title: '提交状态', field: "proStatus",
                //     formatter: function (value, row, index) {
                //         if (value != null) {
                //             if (value === 1) {
                //                 return '<label class="badge label-default">未提交</label>';
                //             } else if (value === 2) {
                //                 return '<label class="badge label-success">已提交</label>';
                //             } else if (value === 3) {
                //                 return '<label class="badge label-success">审核通过</label>';
                //             } else if (value === 4) {
                //                 return '<label class="badge label-danger">被驳回</label>';
                //             }
                //         } else {
                //             return '--';
                //         }
                //     }
                // },
                {title: '工艺编制<br>完成时间', field: "tecComDat", width: '90'},
                {title: '原材料采购<br>回货时间', field: "rawMalRetDat", width: '90'},
                // {title: '机加<br>完成时间', field: "macComDat", width: '90'},
                {title: '生产<br>完成时间', field: "prodComDat", width: '90'},
                {title: '装配<br>完成时间', field: "assComDat", width: '90'},
                // {title: '现场安装<br>完成时间', field: "insComDat", width: '90'},
                {
                    title: '提交状态', field: "proStatus",width: '70',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            if (value === 1) {
                                return '<label class="badge label-default">未提交</label>';
                            } else if (value === 2) {
                                return '<label class="badge label-success">已提交</label>';
                            } else if (value === 5) {
                                return '<label class="badge label-success">审核通过</label>';
                            } else if (value === 4) {
                                return '<label class="badge label-danger">被驳回</label>';
                            }
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '驳回原因', field: "propRejRea",width: '100',
                    formatter: function (value, row, index) {
                        if ((row.propRejReaMin === null && row.propRejReaMin === '') && (row.propRejRea !=null && row.propRejRea !="")) {
                            return "科长驳回原因："+row.propRejRea;
                        }else if (row.propRejReaMin != null && row.propRejReaMin != '' && row.propRejRea !=null && row.propRejRea !='') {
                            return "部长驳回原因："+row.propRejReaMin+"<BR>科长驳回原因："+row.propRejRea;
                        }else if ((row.propRejReaMin != null && row.propRejReaMin != '') && row.propRejRea ===null) {
                            return "部长驳回原因："+row.propRejReaMin;
                        }
                        else {
                            return '--';
                        }
                    }
                },
                {
                    title: '操作', width: '100',
                    formatter: function (value, row, index) {
                        let elements = new Array();
                        if ((row.proStatus === 1 || row.proStatus === 4) && hasP('pro:equipment:edit')) {
                            elements.push('<button class="btn btn-warning btn-xs" onclick="scheduling(' + row.prodId + ')">排产</button>');
                            elements.push('<button class="btn btn-info btn-xs" onclick="showSchedulingPlan(' + row.prodId + ')">查看</button>');
                            if (row.schedulingStatus === 3 && (row.proStatus === 1 || row.proStatus === 4)) {
                                elements.push('<button class="btn btn-success btn-xs" onclick="submitProdOrd(' + row.prodId + ')">提交</button>');
                            }
                        } else if (row.schedulingStatus === 2 && hasP('pro:equipment:view')) {
                            elements.push('<button class="btn btn-info btn-xs" onclick="showSchedulingPlan(' + row.prodId + ')">查看</button>');
                        } else if (row.schedulingStatus === 3 && hasP('pro:equipment:view')) {
                            elements.push('<button class="btn btn-info btn-xs" onclick="showSchedulingPlan(' + row.prodId + ')">查看</button>');
                            // if ((row.proStatus === 1 || row.proStatus === 4) && hasP('pro:equipment:commit')) {
                            //
                            // }
                        }
                        if (row.proStatus === 5 && hasP('pro:equipment:edit')) {
                            elements.push('<button class="btn btn-warning btn-xs" onclick="change(' + row.prodId + ')">变更</button>');
                        }
                        return elements.join('');
                    }
                },
            ]
        });
    }

    /**
     * 创建或编辑总调计划
     */
    function scheduling(prodId) {
        window.open(ctx + 'task/scheduling/edit/' + prodId);
    }

    /**
     * 变更总调计划
     */
    function change(prodId) {
        window.open(ctx + 'task/scheduling/change/' + prodId);
    }

    /**
     * 查看总调计划
     */
    function showSchedulingPlan(prodId) {
        window.open(ctx + 'task/scheduling/see/' + prodId);
    }

    /**
     * 提交总调计划
     */
    function submitProdOrd(prodIdStr) {
        if (prodIdStr === '') {
            let arr = js.table.selectColumns(table, "prodId");
            prodIdStr = arr.join(',');
        }
        js.modal.confirm('尊敬的用户，您确定要提交此排产计划吗？', function () {
            js.post({
                url: ctx + 'task/scheduling/submit',
                type: 'post',
                traditional: true,            // 阻止深度序列化， 使参数可以使用数组
                dataType: 'json',
                contentType: "application/x-www-form-urlencoded",
                data: {
                    prodIdStr: prodIdStr
                },
                async: true,                // 异步执行
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.table.refresh(table);
                },
                error: function () {
                    js.modal.fail();
                }
            });
        });
    }

    /**
     * 重新加载
     */
    function reLoad() {
        js.table.refresh(table);
    }
</script>
</body>
</html>